package com.muzi.onvif.PTZ.requset;


import com.muzi.onvif.beans.OnvifDevice;
import com.muzi.onvif.util.PasswordUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.codec.binary.Base64;

import java.text.MessageFormat;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AbsoluteMoveRequest{
    private String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
            "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tptz=\"http://www.onvif.org/ver20/ptz/wsdl\" xmlns:tt=\"http://www.onvif.org/ver10/schema\">\n" +
            "  <s:Header>\n" +
            "    <wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">\n" +
            "      <wsse:UsernameToken>\n" +
            "        <wsse:Username>{0}</wsse:Username>\n" +
            "        <wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">{1}</wsse:Password>\n" +
            "        <wsse:Nonce>{2}</wsse:Nonce>\n" +
            "        <wsu:Created>{3}</wsu:Created>\n" +
            "      </wsse:UsernameToken>\n" +
            "    </wsse:Security>\n" +
            "  </s:Header>\n" +
            "  <s:Body>\n" +
            "    <tptz:AbsoluteMove>\n" +
            "      <tptz:ProfileToken>{4}</tptz:ProfileToken>\n" +
            "      <tptz:Position>\n" +
            "        <tt:PanTilt x=\"{5}\" y=\"{6}\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace\" />\n" +
            "{7}"+
            "      </tptz:Position>\n" +
            "    </tptz:AbsoluteMove>\n" +
            "  </s:Body>\n" +
            "</s:Envelope>";

    public String getXml(OnvifDevice device,String profileToken,String x,String y) {
        return MessageFormat.format(xml,
                device.getUsername(),
                PasswordUtils.encryptPassword(device.getPassword()),
                Base64.encodeBase64String(PasswordUtils.nonce.getBytes()),
                PasswordUtils.utcTime,
                profileToken,
                x,
                y);

    }
    public String getXml(OnvifDevice device,String profileToken,String x,String y,String z) {
        String zoom = " <tt:Zoom x=\""+z+"\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace\" />";
        return MessageFormat.format(xml,
                device.getUsername(),
                PasswordUtils.encryptPassword(device.getPassword()),
                Base64.encodeBase64String(PasswordUtils.nonce.getBytes()),
                PasswordUtils.utcTime,
                profileToken,
                x,
                y,
                zoom);

    }

}
